<template>
  <div class="common-layout">
    <el-container>
      <!-- 顶部通栏 -->
      <el-header>
        <el-row class="row-bg" justify="center">
          <el-col :span="2">
            <div class="layout-header">
              <img src="https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/e08da34488b114bd4c665ba2fa520a31.svg" alt="" />
            </div>
          </el-col>
          <el-col :span="11">
            <div class="layout-header">
              <div class="menu">
                <myMenu></myMenu>
              </div>
              <div class="brightlogo">
                <img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c99ea7293f8a4907a918af4455bec2c5~tplv-k3u1fbpfcp-zoom-1.gif" alt="" />
              </div>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="layout-header">
              <div class="search">
                <mySearch></mySearch>
              </div>
              <div class="creation">
                <el-dropdown split-button type="primary" trigger="click" @command="handleCommand">
                  发布者中心
                  <template #dropdown>
                    <el-dropdown-menu>
                      <el-dropdown-item command="/editor" :icon="EditPen">写文章</el-dropdown-item>
                      <el-dropdown-item command="/pins" :icon="HotWater"> 发沸点 </el-dropdown-item>
                    </el-dropdown-menu>
                  </template>
                </el-dropdown>
              </div>
              <div class="stickysth">
                <div class="vipimg">
                  <img src="https://lf3-cdn-tos.bytescm.com/obj/static/xitu_juejin_web/img/vip-entry.a14de9c.png" alt="" />
                </div>
                <div>
                  <div v-show="store.state.app.logStatus">
                    <el-button plain @click="handleClickLogin" style="margin-left: 20px">登录</el-button>
                  </div>
                  <div v-show="!store.state.app.logStatus" class="messagebox">
                    <el-badge :value="3" class="messageitem">
                      <el-icon :size="22" color="gray"><BellFilled /></el-icon>
                    </el-badge>
                    <div class="avatarpic">
                      <myAvatar class="navbar-item"></myAvatar>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </el-header>
      <main>
        <!-- 二级路由 -->
        <router-view></router-view>
        <!-- 登录组件 -->
        <dialogLogon v-model="store.state.app.dialogVisible" v-if="store.state.app.dialogVisible"></dialogLogon>
      </main>
    </el-container>
  </div>
</template>

<script setup>
import myMenu from '@/components/layout/menu.vue'
import mySearch from '@/components/layout/search.vue'
import myAvatar from '@/components/layout/avatar.vue'
import dialogLogon from '@/views/login/index.vue'
import { HotWater, EditPen } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
const router = useRouter()
const store = useStore()
const handleClick = () => {
  ElMessage({
    message: '此功能暂未开放，敬请期待',
    type: 'warning'
  })
}
/* 点击登录按钮 */
const handleClickLogin = () => {
  store.commit('app/setDialogVisible')
}
const handleCommand = (command) => {
  if (!store.state.app.logStatus) {
    router.push(command)
  } else {
    ElMessageBox.confirm('您还未登录，是否登录？', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      store.commit('app/setDialogVisible')
    })
  }
}
</script>

<style lang="scss" scoped>
.el-header {
  background-color: #fff;
  .el-menu--horizontal {
    height: 100%;
    border: 0;
  }
}
.layout-header {
  display: flex;
  align-items: center;
  height: 60px;
  background-color: #fff;

  .brightlogo {
    width: 139px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 115px;
      height: 33px;
      object-fit: cover;
    }
  }
  .creation {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 20px;
  }
  .vipimg {
    width: 36px;
    height: 36px;
    margin-left: 20px;
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
.search {
  margin-left: 30px;
  &:focus-within {
    ~ .creation {
      display: none;
    }
  }
}
main {
  padding: 1px 0;
}
.stickysth {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  right: 140px;
}
/* 徽章 */
.messagebox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100px;
  margin-left: 20px;
  .avatarpic {
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    cursor: pointer;
    border: 1px solid #ccc;
    overflow: hidden;
    :deep(.navbar-item) {
      display: inline-block;
      font-size: 22px;
      color: #5a5e66;
      box-sizing: border-box;
      cursor: pointer;
    }
  }
  .messageitem {
    margin-top: 8px;
    cursor: pointer;
    &:hover {
      svg {
        color: $helpColor;
      }
    }
  }
}
</style>
